import numpy as np

def func(x, y, z):
    return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2 + z
    
grid_x, grid_y ,grid_z= np.mgrid[0:1:10j, 0:1:20j, 0:1:200j]
points = np.random.rand(100000, 3)
values = func(points[:,0], points[:,1], points[:,2])

from scipy.interpolate import griddata
# grid_z0 = griddata(points, values, (grid_x, grid_y), method='nearest')
grid_z1 = griddata(points, values, (grid_x, grid_y, grid_z), method='linear')
# grid_z2 = griddata(points, values, (grid_x, grid_y), method='cubic')
ans = func(grid_x, grid_y, grid_z).T

import matplotlib.pyplot as plt
plt.subplot(221)
plt.imshow(ans[:,:,4], extent=(0,1,0,1), origin='lower')
# plt.plot(points[:,1], points[:,2], 'k.', ms=1)
plt.title('Original')
# plt.subplot(222)
# plt.imshow(grid_z0.T, extent=(0,1,0,1), origin='lower')
# plt.title('Nearest')
plt.subplot(223)
plt.imshow(grid_z1.T[:,:,4], extent=(0,1,0,1), origin='lower')
plt.title('Linear')
# plt.subplot(224)
# plt.imshow(grid_z2.T, extent=(0,1,0,1), origin='lower')
# plt.title('Cubic')
plt.gcf().set_size_inches(6, 6)
plt.show()